<?php
include_once './CourseFormatter.php';

header('Content-Type: text/html; charset=utf-8');

$files = $_FILES;

if (empty($files)) {
	result_error('请求的内容为空');
}

if (empty($files['source_file'])) {
	result_error('请选择水晶排课原始课程表');
}

if (empty($files['new_file'])) {
	result_error('请选择排课后的新课程表');
}

$input_filepath = array(
	'week' => $_POST['week'],
	'source_excel' => $files['source_file']['tmp_name'],
	'new_excel' => $files['new_file']['tmp_name'],
);

$new_fileinfo = pathinfo($files['new_file']['name']);

$c = new CourseFormatter($input_filepath);
$c->saved_file_name = basename($new_fileinfo['filename']);
$c->output_to_web = TRUE;
$c->run();

function result_ok($message) {
	echo $message;
	die;
}

function result_error($message) {
	echo $message;
	die;
}

// function _json_result($code, $message) {
// 	$res = array(
// 		'code' => $code,
// 		'message' => $message,
// 	);

// 	echo json_encode($res);
// 	die;
// }

